#!/bin/bash

# You should not use it !

# This is for testing-purposes only

#
# (c) 2009 Mandriva, http://www.mandriva.com/
# (c) 2009 Jean-Dominique Frattini, jd.frattini@free.fr
#
# $Id: $
#
# This file is part of ATS (Automated Testing System), 
# http://http://wiki.mandriva.com/en/Automated_testing_system
#
# ATS is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# ATS is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Pulse 2; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.

# usage: ./this_install.sh

# this file has to be run once under the virtual machine guest in order to 
# install the ATS client (host).
# This step has to be run after the vdi has been created.

while read line
do
   install_dir=$line
   read pkg_name
   read user_name
done < "cfg/install"

mkdir /etc/$pkg_name 2> /dev/null
mkdir /var/log/$pkg_name 2> /dev/null
mkdir $install_dir/share/$pkg_name 2> /dev/null
mkdir $install_dir/share/doc/$pkg_name 2> /dev/null

cp annotate-output.sh $install_dir/bin/
cp testcloud-testrunner.sh $install_dir/bin/
cp timered-sh.sh $install_dir/bin/
cp testcloud-vm-halt.sh $install_dir/bin/
cp README $install_dir/share/doc/$pkg_name/
cp version $install_dir/share/doc/$pkg_name/
cp uninstall.sh $install_dir/share/$pkg_name/
cp ChangeLog $install_dir/share/doc/$pkg_name/
cp cfg/config /etc/$pkg_name/
cp cfg/key /etc/$pkg_name/
cp cfg/install /etc/$pkg_name/

chown $user_name:$user_name $install_dir/bin/annotate-output.sh
chown $user_name:$user_name $install_dir/bin/testcloud-testrunner.sh
chown $user_name:$user_name $install_dir/bin/timered-sh.sh
chmod 700 $install_dir/bin/annotate-output.sh
chmod 700 $install_dir/bin/testcloud-testrunner.sh
chmod 700 $install_dir/bin/timered-sh.sh
chmod 700 $install_dir/bin/testcloud-vm-halt.sh

chmod 700 $install_dir/share/$pkg_name/uninstall.sh
chown -R $user_name:$user_name $install_dir/share/doc/$pkg_name
chmod 644 $install_dir/share/doc/$pkg_name/README
chmod 644 $install_dir/share/doc/$pkg_name/ChangeLog

chown -R $user_name:$user_name /etc/$pkg_name
chmod 700 /etc/$pkg_name
chmod 400 /etc/$pkg_name/*

echo "testcloud-testrunner client succesfully installed if no error were printed on screen."
